//
//  WPPPickerTopView.m
//  LoveIN
//
//  Created by bst on 2019/7/2.
//  Copyright © 2019 bst. All rights reserved.
//

#import "WPPPickerTopView.h"
@interface WPPPickerTopView ()
@property(nonatomic,strong)UIButton *closeButton;
@property(nonatomic,strong)UIButton *sureButton;
@property(nonatomic,strong)UILabel *titleLab;
@property(nonatomic,strong)UILabel *subTitleLab;
@end
@implementation WPPPickerTopView
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self titleLab];
        [self subTitleLab];
        
        [self closeButton];
        [self sureButton];
    }
    return self;
}
- (void)dealloc
{
    NSLog(@"WPPPickerTopView ---dealloc");
}
- (void)setTitle:(NSString *)title
{
    _title = title;
    self.titleLab.text = title;
}
- (void)setSubTitle:(NSString *)subTitle
{
    _subTitle = subTitle;
    self.subTitleLab.text = subTitle;
}
#pragma mark - click
- (void)clickItemButton:(UIButton *)sender
{
    !self.callBackTypeBlock ?: self.callBackTypeBlock (sender.tag);
}
#pragma mark - lazy懒加载
- (UILabel *)titleLab
{
    if (!_titleLab) {
        UILabel *lab = [[UILabel alloc]init];
        [self addSubview:lab];
        lab.font = [UIFont systemFontOfSize:15*ADAPTER_WIDTH weight:UIFontWeightRegular];
        lab.textColor = rgba(0, 0, 0, 1);
        lab.textAlignment = NSTextAlignmentCenter;
        lab.numberOfLines = 1;
        lab.frame = CGRectMake(35*ADAPTER_WIDTH, 17*ADAPTER_WIDTH, self.width - 70*ADAPTER_WIDTH, 16*ADAPTER_WIDTH);
        _titleLab = lab;
    }
    return _titleLab;
}
- (UILabel *)subTitleLab
{
    if (!_subTitleLab) {
        UILabel *lab = [[UILabel alloc]init];
        [self addSubview:lab];
        lab.font = [UIFont systemFontOfSize:13*ADAPTER_WIDTH weight:UIFontWeightRegular];
        lab.textColor = rgba(0, 0, 0, 1);
        lab.textAlignment = NSTextAlignmentCenter;
        lab.numberOfLines = 1;
        lab.frame = CGRectMake(10*ADAPTER_WIDTH, 10*ADAPTER_WIDTH + self.titleLab.bottom, self.width - 20*ADAPTER_WIDTH, 14*ADAPTER_WIDTH);
        _subTitleLab = lab;
    }
    return _subTitleLab;
}
- (UIButton *)closeButton
{
    if (!_closeButton) {
        CGFloat itemWidth = [@"取消" sizeWithFont:kFontRegular(18*ADAPTER_WIDTH)].width;
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:button];
        button.frame = CGRectMake(0, 0, itemWidth + 32*ADAPTER_WIDTH, 19*ADAPTER_WIDTH + 30*ADAPTER_WIDTH);//14x14
        button.titleEdgeInsets = UIEdgeInsetsMake(15*ADAPTER_WIDTH, 16*ADAPTER_WIDTH, 15*ADAPTER_WIDTH, 16*ADAPTER_WIDTH);
        [button setTitle:@"取消" forState:UIControlStateNormal];
        [button setTitleColor:rgba(255, 146, 92, 1) forState:UIControlStateNormal];
        button.titleLabel.font = kFontRegular(18*ADAPTER_WIDTH);
        button.tag = 1;
        [button addTarget:self action:@selector(clickItemButton:) forControlEvents:UIControlEventTouchUpInside];
        _closeButton = button;
    }
    return _closeButton;
}
- (UIButton *)sureButton
{
    if (!_sureButton) {
        CGFloat itemWidth = [@"确定" sizeWithFont:kFontRegular(18*ADAPTER_WIDTH)].width;
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:button];
        button.frame = CGRectMake(self.width - 32*ADAPTER_WIDTH - itemWidth, 0, itemWidth + 32*ADAPTER_WIDTH, 19*ADAPTER_WIDTH + 30*ADAPTER_WIDTH);//14x14
        button.titleEdgeInsets = UIEdgeInsetsMake(15*ADAPTER_WIDTH, 16*ADAPTER_WIDTH, 15*ADAPTER_WIDTH, 16*ADAPTER_WIDTH);
        [button setTitle:@"确定" forState:UIControlStateNormal];
        [button setTitleColor:rgba(255, 146, 92, 1) forState:UIControlStateNormal];
        button.titleLabel.font = kFontRegular(18*ADAPTER_WIDTH);
        button.tag = 0;
        [button addTarget:self action:@selector(clickItemButton:) forControlEvents:UIControlEventTouchUpInside];
        _sureButton = button;
    }
    return _sureButton;
}
@end
